<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<style type="text/css">
		#main {
			width: 400px;
		}
	</style>

	<body>

		<form id="main" onsubmit="return yanzheng()">
			<p><label for="name">用户名：</label><input type="text" name="name" id="name" onblur="yanzheng()" /></p>
			<p><label for="password">密&nbsp;&nbsp;&nbsp;&nbsp;码：</label><input type="password" name="password" id="password" /></p>
			<p><label for="email">邮&nbsp;&nbsp;&nbsp;&nbsp;箱：</label><input type="text" name="email" id="email" /></p>
			<p><label for="year">生&nbsp;&nbsp;&nbsp;&nbsp;日：</label><input type="text" name="year" id="year" size="2" />年<input type="text" name="month" id="month" size="2" />月<input type="text" name="day" id="day" size="2" />日</p>
			<input type="submit" />
		</form>

		<script type="text/javascript">
			function getId(id) {
				return document.getElementById(id);
			}

			function yanzheng() {
				var name = getId("name").value;
				var password = getId("password").value;
				var email = getId("email").value;
				var year = getId("year").value;
				var month = getId("month").value;
				var day = getId("day").value;
				var index1 = email.indexOf("@")
				var index2 = email.lastIndexOf(".")
				var date = new Date();
				if(name != "") {
					if(password.length >= 4 && password.length <= 16) {
						if(index1 > 0 && index2 > 0 && index2 - index1 > 1) {
							if(year.length == 4 && year > 1900 && year <= date.getFullYear()) {
								if(month.toString() >= 1 && month.toString() <= 12) {
									if((month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) && day > 0 && day < 32) {
										confirm("信息已填完，确定注册？");
										return true;
									}
									if((month == 4 || month == 6 || month == 9 || month == 11) && day > 0 && day <= 30) {
										confirm("信息已填完，确定注册？");
										return true;
									}

									if(month == 2 && (isRunNian(year) == true) && day > 0 && day <= 29) {
										confirm("信息已填完，确定注册？");
										return true;
									}
									if(month == 2 && (isRunNian(year) == false) && day > 0 && day <= 28) {
										confirm("信息已填完，确定注册？");
										return true;
									} else {
										confirm("请输入正确的天数")
										return false;
									}
								} else {
									confirm("请输入正确的月份")
									return false;
								}
							} else {
								confirm("请输入正确的年份")
								return false;
							}
						} else {
							confirm("请输入正确的邮箱格式")
							return false;
						}
					} else {
						confirm("请输入4~16位密码");
						return false;
					}
				} else {
					confirm("用户名不能为空")
					console.log(year.toString() > 1000)
					return false;
				}
			}

			function isRunNian(nian) {
				return nian % 4 == 0 && nian % 100 != 0 || nian % 400 == 0;
			}
		</script>
	</body>

</html>